***************************************************
*Replication: Are we all predictably irrational?  *
*Political Behavior                               *
*John A. Doces and Amy Wolaver                    *
***************************************************

*Set directory here

*****Summary Data for Figure 1******

*Ivory Coast

use "Ivory Coast data", clear

gen certain_q1_v1=.
replace certain_q1_v1=1 if Q1_version==1 & Q1_Answer==1
replace certain_q1_v1=0 if Q1_version==1 & Q1_Answer==0
label variable certain_q1_v1 "Answered Yes to Save"

gen certain_q1_v2=.
replace certain_q1_v2=1 if Q1_version==2 & Q1_Answer==1
replace certain_q1_v2=0 if Q1_version==2 & Q1_Answer==0
label variable certain_q1_v2 "Answered Yes to Die"

sum certain_q1_v1 certain_q1_v2 /*note this is summary data used for Fig 1
 for the Ivory Coast*/
 
*Ghana

use "Ghana Data", clear

gen certain_q1_v1=.
replace certain_q1_v1=1 if Q1_version==1 & Q1_Answer==1
replace certain_q1_v1=0 if Q1_version==1 & Q1_Answer==0
label variable certain_q1_v1 "Answered Yes to Save"

gen certain_q1_v2=.
replace certain_q1_v2=1 if Q1_version==2 & Q1_Answer==1
replace certain_q1_v2=0 if Q1_version==2 & Q1_Answer==0
label variable certain_q1_v2 "Answered Yes to Die"

sum certain_q1_v1 certain_q1_v2 /*note this is summary data used for Fig 1
 for Ghana*/

*U.S. 

use "US Data", clear

gen certain_q1_v1=.
replace certain_q1_v1=1 if Q32a==1 | Q32b==2
replace certain_q1_v1=0 if Q32a==2 | Q32b==1
label variable certain_q1_v1 "Yes to Save"

gen certain_q1_v2=.
replace certain_q1_v2=1 if Q32c==1 | Q32d==2
replace certain_q1_v2=0 if Q32c==2 | Q32d==1
label variable certain_q1_v2 "Yes to Die"

sum certain_q1_v1 certain_q1_v2 /*note this is summary data used for Fig 1
 for U.S.*/
 

*****Summary Data for Figure 2*****

* Ivory Coast

use "Ivory Coast Data",clear

gen yes_q2_v1=.
replace yes_q2_v1=1 if Q2_version==1 & Q2==1
replace yes_q2_v1=0 if Q2_version==1 & Q2==0
label variable yes_q2_v1 "Answered Yes to High Price"

gen yes_q2_v2=.
replace yes_q2_v2=1 if Q2_version==2 & Q2==1
replace yes_q2_v2=0 if Q2_version==2 & Q2==0
label variable yes_q2_v2 "Answered Yes to Low Price"

sum yes_q2_v1 yes_q2_v2

* Ghana

use "Ghana Data",clear

gen yes_q2_v1=.
replace yes_q2_v1=1 if Q2_version==1 & Q2==1
replace yes_q2_v1=0 if Q2_version==1 & Q2==0
label variable yes_q2_v1 "Answered Yes to High Price"

gen yes_q2_v2=.
replace yes_q2_v2=1 if Q2_version==2 & Q2==1
replace yes_q2_v2=0 if Q2_version==2 & Q2==0
label variable yes_q2_v2 "Answered Yes to Low Price"

sum yes_q2_v1 yes_q2_v2

* U.S.

use "US Data",clear

gen yes_q2_v1=.
replace yes_q2_v1=1 if Q33b==1 
replace yes_q2_v1=0 if Q33b==2
label variable yes_q2_v1 "Answered Yes to High Price"

gen yes_q2_v2=.
replace yes_q2_v2=1 if Q33a==1
replace yes_q2_v2=0 if Q33a==2
label variable yes_q2_v2 "Answered Yes to Low Price"

sum yes_q2_v1 yes_q2_v2

*****Creating FIGURES 1 and 2*****

*Figure 1

clear

set obs 3

gen source= ""
replace source="Cote d'Ivoire" in 1
replace source="Ghana" in 2
replace source="U.S." in 3

gen certain_save=.
replace certain_save=71 in 1
replace certain_save=66 in 2
replace certain_save=63 in 3
graph bar certain_save, title(Save Frame) ytitle(Percent) over(source) ///
 blabel(bar, pos(inside)) yline(72)
graph save Figure_save.gph,replace


gen certain_death=.
replace certain_death=57 in 1
replace certain_death=65 in 2
replace certain_death=31 in 3
graph bar certain_death, title(Death Frame) ytitle(Percent) over(source) ///
 blabel(bar,pos(inside)) yline(22)
graph save Figure_death.gph,replace


graph combine Figure_save.gph Figure_death.gph, ycommon xcommon ///
title (Figure 1. Percent Preferring the Certain Option over the Gamble by Frame)
graph save Figure_1.gph,replace 

*Figure 2 

gen save_money_low=.
replace save_money_low=59 in 1
replace save_money_low=66 in 2
replace save_money_low=40 in 3
graph bar save_money_low, title(Low Price Frame) ytitle(Percent) ///
over(source) blabel(bar, pos(inside)) yline(68)
graph save Figure_lowprice.gph,replace

gen save_money_high=.
replace save_money_high=66 in 1
replace save_money_high=73 in 2
replace save_money_high=27 in 3
graph bar save_money_high, title(High Price Frame) ytitle(Percent) over(source) blabel(bar,pos(inside)) yline(29)
graph save Figure_highprice.gph,replace


graph combine Figure_lowprice.gph Figure_highprice.gph, ycommon xcommon ///
title("Figure 2. Percent Choosing to Save Money by Frame") ///
note("Source: Authors' calculations based on 2018 data. Horizontal lines represent the Tversky and Kahneman (1981) benchmark results", size(tiny))
graph save Figure_2.gph,replace 

*****Regression Analysis*****

use "Full Data", clear

*Variables

gen Africa=.
replace Africa=1 if country_code==1 | country_code==2
replace Africa=0 if country_code==3

label define Africa_lab 0 "U.S." 1 "Africa"
label values Africa Africa_lab

label define save_lab 0 "Death Frame" 1 "Save Frame"
label values save_treatment save_lab

label define price_lab 0 "High Price" 1 "Low Price"
label values low_price_treatment price_lab

*Analysis 

*Certain response for save/death, developing and developed
logit certain_response i.Africa#i.save_treatment i.female_r i.education_r i.ideology_r i.age_bracket_r
coefplot,eform xline(1) baselevels keep(*Africa#*save_treatment) ///
title("Figure 3. Effect of Policy Treatment, Developing vs. Developed") ///
xtitle("Odds Ratio")
graph save Figure_3.gph,replace 


logit save_money i.Africa#i.low_price_treatment i.female_r i.education_r i.ideology_r i.age_bracket_r
coefplot,eform xline(1) baselevels keep(*Africa#*low_price_treatment) ///
title("Figure 4. Effect of Price Treatment, Developing vs. Developed") ///
xtitle("Odds Ratio")
graph save Figure_4.gph,replace 


*Certain response for save/death, developing and developed

recode economic_class_r (0=3 "Poor") (1=2 "Middle") (2=1 "Upper Middle") (3=0 "Rich"),gen(economic_class_r_rev)

logit certain_response i.economic_class_r_rev#i.save_treatment i.female_r i.education_r i.ideology_r i.age_bracket_r,r
coefplot,eform xline(1) baselevels keep(*economic_class_r_rev#*save_treatment) ///
title("Figure 5. Effect of Policy Treatment, by Income Level") ///
xtitle("Odds Ratio")
graph save Figure_5.gph,replace 


logit save_money i.economic_class_r_rev#i.low_price_treatment i.female_r i.education_r i.ideology_r i.age_bracket_r
coefplot,eform xline(1) baselevels keep(*economic_class_r_rev#*low_price_treatment) ///
title("Figure 6. Effect of Price Treatment, by Income Level") ///
xtitle("Odds Ratio")
graph save Figure_6.gph,replace 
